#include "game.hpp"

/*args: windowSizeX, windowSizeY, size of one block, size of paddings*/

Game::Game(uin sFx, uin sFy, uin sB, uin sP)
    : rows((sFy - sP) / (sB + sP)), columns((sFx - sP) / (sB + sP)),
      sizeField(rows * columns),
      paddingX((sFx - (columns * (sB + sP) - sP)) / 2),
      paddingY((sFy - (rows * (sB + sP) - sP)) / 2) {

  field.resize(sizeField);

  for (uin cx = 0, cy = 0; auto &[x, y] : field) {
    x = paddingX + cx++ * (sB + sP);
    y = paddingY + cy * (sB + sP);
    if (cx == columns) {
      ++cy;
      cx = 0;
    }
  }
}

const std::vector<std::pair<unsigned int, unsigned int>> &Game::getField() {
  return field;
}

const std::pair<unsigned int, unsigned int> Game::Size() {
  return std::make_pair(columns, rows);
}

void Game::gameover() { std::exit(0); }

void Game::new_food(unsigned int seed) {
  std::srand(seed);
  foodCord = std::rand() % sizeField;
}
const unsigned int Game::get_food_cord() { return foodCord; }
